<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Restricted access');

class JElementK2categories extends JElement{
	var $_name = 'K2categories';

	function fetchElement($name, $value, &$node, $control_name)
	{
		if(file_exists(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'k2.php')){
			$result = '<script type="text/javascript">
					window.addEvent(\'domready\',function(){
						if(document.getElementById("k2_categories_btn").checked){
							document.getElementById("listk2_categories").style.visibility="visible";
							document.getElementById("desc_k2_categories").style.visibility="hidden";
						}else {
							document.getElementById("listrsmembership_categories").style.visibility="hidden";
							document.getElementById("desc_rsmembership_categories").style.visibility="visible";
						}
					});
					</script>';
			$result .= '<div id="desc_k2_categories" style="visibility:visible;margin-top: 27px;">'.JText::_('RSF_K2_CATEGORIES_LIST_DESC').'</div>';
			$result .= '<div id="listk2_categories" style="visibility:hidden;">';
	
				$db =& JFactory::getDBO();
				$query = "SELECT * FROM #__k2_categories ORDER BY `name` ASC";
				$db->setQuery($query);
				$cats = $db->loadObjectList();
	
			$result .= JHTML::_('select.genericlist', $cats, $control_name.'[categories][]', 'multiple="multiple"', 'id', 'name', $value);
			$result .= '</div>';
		} else $result = 'You need to install K2 Component in order to use RSSearch! for K2 plugin. You can download K2 component from <a href="http://getk2.org/" target="_blanc">here</a>';

		return $result;
	}
}